﻿using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.Office.Server.Search;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server.Search.Query;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using MediawikiSPMigratorClass;

namespace MediawikiSPMigratorTests
{
    [TestClass]
    public class SharePointDataTests
    {
        [TestMethod]
        public void GetUserIDTest()
        {
            string filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", "mcdonnk");
            string domain = "SCHRODERSAD";
            string[] properties = new string[] { "fullname" };
            DirectoryEntry adRoot = new DirectoryEntry("LDAP://SCHRODERSAD", null, null, AuthenticationTypes.Secure);
            DirectorySearcher searcher = new DirectorySearcher(adRoot);
            searcher.SearchScope = SearchScope.Subtree;
            searcher.ReferralChasing = ReferralChasingOption.All;
            searcher.PropertiesToLoad.AddRange(properties);
            searcher.Filter = filter;
            SearchResult result = searcher.FindOne();
            DirectoryEntry directoryEntry = result.GetDirectoryEntry();
        }
    /*    [TestMethod]
        public void ProcessStringFieldTest()
        {
            SPList list = new SPList();
            Dictionary<string, Dictionary<string, string>> templateDetails = new Dictionary<string,Dictionary<string,string>>();
            SharePointData SPData = new SharePointData(list, templateDetails);
            XElement field = XElement.Parse("<Field Source=\"avail\" Type=\"Text\" Destination=\"Availability\" />");
            PublishingPage newPage = new PublishingPage();
            SPData.ProcessStringField(field, newPage, "Application");
        }

        [TestMethod]
        public void ProcessMetadataFieldTest()
        {
            SPList list = new SPList();
            Dictionary<string, Dictionary<string, string>> templateDetails = new Dictionary<string, Dictionary<string, string>>();
            SharePointData SPData = new SharePointData(list, templateDetails);
            XElement field = XElement.Parse("<Field Source=\"recovery\" Type=\"Metadata\" Destination=\"Recovery Status\" MetadataField=\"Recovery Status\"/>");
            PublishingPage newPage = new PublishingPage();
            SPData.ProcessMetadataField(field, newPage, "Application");
        }
        */
        //[TestMethod]
        public void ProcessFieldsFromTemplateMappingTest()
        {
            MappingData mapping = new MappingData();
            XElement actual = mapping.GetMappingDetails("Application");
            int expectedFieldCount = 14;

            Assert.IsTrue(actual.Descendants().Count() == expectedFieldCount);
        }
    }
}
